﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Test;

namespace work08
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void refresh1()
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate () {
                var crawl = new Crawl("https://www.baidu.com/s?wd=" + input.Text);
                Output1.Text = crawl.get();
            });
        }

        private void refresh2()
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate () {
                var crawl = new Crawl("https://www.baidu.com/s?wd=" + input.Text);
                Output2.Text = crawl.get();
            });
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Thread childThread1 = new Thread(refresh1);
            Thread childThread2 = new Thread(refresh2);
            childThread1.Start();
            childThread2.Start();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Parallel.Invoke(refresh1, refresh2);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Task task1 = Task.Run(() =>
            {
                refresh1();
            });

            Task task2 = Task.Run(() =>
            {
                refresh2();
            });

        }
    }
}
